package com.itheima.server.controller;

import com.itheima.model.vo.PageResult;
import com.itheima.model.vo.UserInfoVo;
import com.itheima.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /*根据环信id查询用户信息*/
    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huanxinId){
        UserInfoVo vo = messageService.findUserInfoByHuanxin(huanxinId);
        return ResponseEntity.ok(vo);
    }
    /*联系人添加*/
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map<String,String> map){
        Long friendId = Long.valueOf(map.get("userId"));
        messageService.contacts(friendId);
        return ResponseEntity.ok(null);
    }
    /*联系人列表*/
    @GetMapping("/contacts")
    public ResponseEntity contacts(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String keyword){
       PageResult pageResult= messageService.findFriends(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 分页查询公告列表
     */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messageService.getAnnouncements(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 评论列表
     */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messageService.getComments(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 点赞列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messageService.getLikes(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     * 喜欢列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = messageService.getLoves(page,pagesize);
        return ResponseEntity.ok(pr);
    }
}
